package com.tau.iplayer.client;

import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.tau.iplayer.client.exceptions.NotLoggedInException;
import com.tau.iplayer.client.models.Playlist;
import com.tau.iplayer.client.models.Track;
import com.tau.iplayer.client.models.TrackTransaction;

@RemoteServiceRelativePath("datastore")
public interface DataStoreService extends RemoteService {
	
	/**
	 * stores the track with the given playlist
	 * @param track the track to store
	 * @param playlist the playlist which includes this track
	 * @throws NotLoggedInException
	 */
	void addTrack(String userID, Track track, Playlist playlist) throws NotLoggedInException;
	
	/**
	 * gets the playlists from the data store
	 * @return the stored playlists
	 * @throws NotLoggedInException
	 */
	Map<String, Playlist> getPlaylists(String userID) throws NotLoggedInException;
	
	List<Track> getTracks(String userID, Playlist playlist) throws NotLoggedInException;
	
	/**
	 * stores a playlist
	 * @param playlist the playlist to store
	 */
	public void addPlaylist(String userID, Playlist playlist) throws NotLoggedInException;
	
	/**
	 * deletes a track from the data store
	 * @param track the track to delete
	 * @throws NotLoggedInException
	 */
	void deleteTrack(String userID, Track track) throws NotLoggedInException;
	
	/**
	 * updates a track
	 * @param newTrack the updated track
	 * @throws NotLoggedInException
	 */
	void updateTrack(String userID, Track newTrack) throws NotLoggedInException;
	
	/**
	 * moves a track and place it in to a new playlist
	 * @param track the track to move
	 * @param newPlaylist the playlist to move the track to
	 * @throws NotLoggedInException
	 */
	void moveTrack(String userID, Track track, Playlist newPlaylist) throws NotLoggedInException;
	
	/**
	 * updates a playlist to the given playlist
	 * @param playlist the playlist to update
	 * @param name TODO
	 * @throws NotLoggedInException
	 */
	void renamePlaylist(String userID, Playlist playlist, String name) throws NotLoggedInException;
	
	/**
	 * deletes a playlist
	 * @param playlist the playlist to delete
	 * @throws NotLoggedInException
	 */
	void deletePlaylist(String userID, Playlist playlist) throws NotLoggedInException;
	
	/**
	 * gets all the tracks, with positive rating, that belong to the given users
	 * @param userIDs the users. first id is the current viewer
	 * @return the tracks
	 * @throws NotLoggedInException
	 */
	List<Track> getTracks(List<String> userIDs) throws NotLoggedInException;
	
	/**
	 * gets all the tracks, with positive rating, in the DB
	 * @return all tracks
	 */
	List<Track> getAllTracks();
	
	/**
	 * stores s given track transaction in the DB
	 * @param transaction the transaction to store
	 * @throws NotLoggedInException
	 */
	void storeTrackTransaction(TrackTransaction transaction) throws NotLoggedInException;
	
	/**
	 * gets all the tracks that were sent to the given user
	 * @param receiverID the user id
	 * @return the list of tracks which were sent
	 * @throws NotLoggedInException
	 */
	List<TrackTransaction> getTrackTransactions(String receiverID) throws NotLoggedInException;
	
	/**
	 * deletes the given track transaction from the db
	 * @param transaction the transaction to delete
	 */
	void deleteTrackTransaction(String userID, TrackTransaction transaction) throws NotLoggedInException;
}
